<!DOCTYPE html>
<html class="x-admin-sm">
	{include file="public/_header" /}
	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>回收站</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
			 title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
		</div>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<table class="layui-hide" id="test" lay-filter="test"></table>
							<script type="text/html" id="barDemo">
								<a class="layui-btn layui-btn-xs" lay-event="reduction">还原</a>
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
							</script>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		$(function() {
			layui.use(['table', 'util'], function() {
				var table = layui.table;
				var util = layui.util;
				var form = layui.form;

				var tableInfo = table.render({
					elem: '#test',
					url: "{:url('admin/Recycle/recycle_lists')}",
					title: '用户数据表',
					cols: [
							[{
								field: 'id',
								fixed: 'left',
								title: 'id',
								width: 80
							},
							{
								field: 'title',
								title: '标题',
								width: 300,
								templet: function(d) {
									var str = '<span style="color:' + d.titlecolor + '">' + d.title + '</span>';
									return str;
								}
							},
							{
								field: 'click',
								title: '点击次数',
								sort: true,
								width: 100,
							},
							{
								field: 'inputtime',
								title: "{:lang('inputtime')}",
								sort: true,
								templet: function(d) {
									var logoSrc = util.toDateString(d.inputtime * 1000, "yyyy-MM-dd HH:mm:ss");
									return logoSrc;
								}
							}, {
								field: 'updatetime',
								title: "{:lang('updatetime')}",
								templet: function(d) {
									var logoSrc = util.toDateString(d.updatetime * 1000, "yyyy-MM-dd HH:mm:ss");
									return logoSrc;
								},
								sort: true
							},
							{
								field: 'category_name',
								title: "{:lang('category_name')}"
							},
							{
								fixed: 'right',
								title: '操作',
								toolbar: '#barDemo'
							}
						]
					],
					page: {
						limit: 10
					}
				});

				//头工具栏事件
				table.on('toolbar(test)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case 'getCheckData':
							var data1 = checkStatus.data;
							if (data1.length == 0) {
								layer.msg("你必须选择一项");
								return false;
							}
							layer.confirm('确认要删除这些文章么?', {
								icon: 3,
								title: '提示'
							}, function(index) {
								layer.close(index);
								var data = checkStatus.data;
								var str = "";
								data.forEach(function(item, index) {
									str += item.aid + ','
								})
								$.ajax({
									type: "post",
									url: "{:url('admin/article/delete_status')}",
									data: {
										aid: str,
										value: 1,
										table: $("#table").val()
									},
									dataType: "json",
									success: function(res) {
										if (res.data) {
											layer.msg('修改成功', {
												icon: 1,
												time: 500 //2秒关闭（如果不配置，默认是3秒）
											}, function() {
												tableInfo.reload();
											});

										} else {
											layer.msg('修改失败', {
												icon: 2,
												time: 4000 //2秒关闭（如果不配置，默认是3秒）
											}, function() {
												tableInfo.reload();
											});
										}
									},
								});
							}, function(index) {

							});

							break;
						case 'isAll':
							layer.msg(checkStatus.isAll ? '全选' : '未全选');
							break;
					};
				});

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					console.log(data);
					if (obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							$.ajax({
								type: "post",
								url: "{:url('admin/Recycle/data_delete')}",
								data: {
									id:data.id,
									aid: data.aid,
									model_id: data.model_id,
									table_name: data.table_name
								},
								dataType: "json",
								success: function(res) {
									if (res.status == 0) {
										layer.msg('删除成功', {
											icon: 1,
											time: 500 //2秒关闭（如果不配置，默认是3秒）
										}, function() {
											tableInfo.reload();
										});

									} else {
										layer.msg('删除失败', {
											icon: 2,
											time: 4000 //2秒关闭（如果不配置，默认是3秒）
										}, function() {
											tableInfo.reload();
										});
									}
								},
							});

						});
					}else if(obj.event === 'reduction'){
						$.ajax({
							type: "post",
							url: "{:url('admin/Recycle/reduction')}",
							data: {
								table_name:data.table_name,
								id:data.id,
								aid:data.aid
							},
							dataType: "json",
							success: function(res) {
								if (res.status == 0) {
									layer.msg('还原成功', {
										icon: 1,
										time: 500 //2秒关闭（如果不配置，默认是3秒）
									}, function() {
										tableInfo.reload();
									});
						
								} else {
									layer.msg('还原失败', {
										icon: 2,
										time: 4000 //2秒关闭（如果不配置，默认是3秒）
									}, function() {
										tableInfo.reload();
									});
								}
							},
						});
						
					}
				});

				form.on('switch(status)', function(obj) {
					$.ajax({
						type: "get",
						url: "{:url('admin/Article/show')}",
						data: {
							table: $("#table").val(),
							aid: this.value,
							value: obj.elem.checked ? 1 : 0
						},
						dataType: "json",
						success: function(res) {
							if (res.data) {
								layer.msg('修改成功', {
									icon: 1,
									time: 2000 //2秒关闭（如果不配置，默认是3秒）
								});

							} else {
								layer.msg('修改失败', {
									icon: 2,
									time: 4000 //2秒关闭（如果不配置，默认是3秒）
								}, function() {
									tableInfo.reload();
								});
							}
						},
					});

				});


			});


		})
	</script>
</html>
